import csv
import math


def run_length_encoding(sequence):
    if not sequence:
        return []

    encoded_sequence = []
    count = 1

    for i in range(1, len(sequence)):
        if sequence[i] == sequence[i - 1]:
            count += 1
        else:
            encoded_sequence.append(count)
            count = 1

    encoded_sequence.append(count)
    if sequence[0] != 1:
        encoded_sequence.insert(0, 0)

    return encoded_sequence

# print(run_length_encoding([1,1,1,1,-1,-1,-1,1,1,1,-1]))
# print(run_length_encoding([-1,1,1,1,1,-1,-1,-1,1,1,1,-1]))


def get_all_cyclic_groups(csv_file):
    result = []
    with open(csv_file, 'r') as file:
        reader = csv.reader(file)
        for row in reader:
            if len(row) == 3 and row[-1]==" true":
                result.append((int(row[0]), int(row[1])))
    return result


# cyclic_groups = get_all_cyclic_groups("/home/eric/dev/dsp/data/ds/cyclic-groups.csv")
# print(len(cyclic_groups))
# print(cyclic_groups)

def is_prime_power(num):
    """
    Checks if a number is a prime power.
    """
    if num <= 1:
        return False
    if is_prime(num):
        return True
    for i in range(2, int(math.sqrt(num)) + 1):
        if is_prime(i):
            exponent = 2
            while i**exponent <= num:
                if i**exponent == num:
                    return True
                exponent += 1
    return False

def is_prime(n):
    if n <= 1:
        return False
    elif n <= 3:
        return True
    elif n % 2 == 0 or n % 3 == 0:
        return False
    i = 5
    while i * i <= n:
        if n % i == 0 or n % (i + 2) == 0:
            return False
        i += 6
    return True

# print(is_prime_power(2))
# print(is_prime_power(3))
# print(is_prime_power(4))
# print(is_prime_power(5))
# print(is_prime_power(6))
# print(is_prime_power(7))
# print(is_prime_power(8))
# print(is_prime_power(9))
# print(is_prime_power(10))

def get_primes():
    result = []
    for i in range(2,100):
        if is_prime(i):
            result.append(i)
    return result

def get_prime_powers():
    primes = get_primes()
    prime_powers = []
    for prime in primes:
        power = prime
        while power < 100:
            prime_powers.append(power)
            power *= prime

    return prime_powers

# primes = get_primes()
# print(primes)
# powers = get_prime_powers()
# print(powers)


def get_all_prime_power():
    return [2, 4, 8, 16, 32, 64, 3, 9, 27, 81, 5, 25, 7, 49, 11, 13, 17, 19, 23, 29, 31, 37, 41, 43, 47, 53, 59, 61, 67, 71, 73, 79, 83, 89, 97]

def get_all_singer_ds():
    powers = get_all_prime_power()
    singers = []
    for q in powers:
        for n in range(2,10):
            if((q**(n+1) - 1)/(q-1) < 100):
                singers.append((int((q**(n+1) - 1)/(q-1)), int((q**n - 1)/(q-1)), int((q**(n-1) - 1)/(q-1))))
    return singers

print(get_all_singer_ds())